package com.crm.service.impl;

import com.crm.dao.ServiceMapper;
import com.crm.domain.DataGridView;
import com.crm.pojo.Service;
import com.crm.service.ServiceMangerService;
import com.crm.vo.ServiceVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
@org.springframework.stereotype.Service
public class ServiceMangerServiceImpl implements ServiceMangerService {
    @Autowired
    private ServiceMapper serviceMapper;
    @Override
    public DataGridView getServiceListByPage(ServiceVo serviceVo) {
        Page<Object> page= PageHelper.startPage(serviceVo.getPage(),serviceVo.getLimit());
        List<Service> data=this.serviceMapper.selectServiceByProperty(serviceVo);
        System.out.println(data);
        return new DataGridView(page.getTotal(),data);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean addService(Service service) {
        boolean flag=false;
        this.serviceMapper.insertService(service);
        flag=true;
        return flag;
    }

    @Override
    public void removeService(Integer id) {
        this.serviceMapper.deleteByid(id);
    }

    @Override
    public void removeBatchService(Integer[] ids) {
        for(Integer id:ids){
            this.removeService(id);
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean addAssagn(int id, String assignee, Date distributeTime) {
        boolean flag=false;
        this.serviceMapper.updatAssign(id,assignee,distributeTime);
        flag=true;
        return flag;
    }

    @Override
    public boolean addDeal(int id, String serviceDeal, String conductor, Date dealTime) {
        boolean flag=false;
        this.serviceMapper.updatDeal(id,serviceDeal,conductor,dealTime);
        flag=true;
        return flag;
    }

    @Override
    public boolean addResponse(int id, String dealResrult, String satisfaction) {
        boolean flag=false;
        this.serviceMapper.updatResponse(id,dealResrult,satisfaction);
        flag=true;
        return flag;
    }
}
